# -*- coding: utf-8 -*-
from datetime import datetime
from django.core.urlresolvers import reverse
from main.models import Employee
from django.db import models

class Promotion(models.Model):
    title = models.CharField(u'Название', max_length=250)
    note = models.CharField(u'Примечание', max_length=255, blank=True)

    def __unicode__(self):
        return self.title

    def get_awarded(self):
        return AwardedEmployee.objects.filter(promotion=self)

    def get_absolute_url(self):
        return reverse('promotion_detail', args=[self.pk])

    class Meta:
        verbose_name = u'список поощрение'
        verbose_name_plural = u'Список поощрений'
        permissions = (
            ("can_view_promotion", u"Поощрения - просмотр."),
        )

class AwardedEmployee(models.Model):
    promotion = models.ForeignKey('Promotion', verbose_name=u'Поощрение')
    employee = models.ForeignKey(Employee, verbose_name=u'Сотрудники', help_text=u'Список поощрённых сотрудников!')
    award_date = models.CharField(verbose_name=u'Год награждения', default=datetime.now().year, max_length=4)

    def __unicode__(self):
        return u'%s - %s' % (self.promotion, self.award_date)

    class Meta:
        verbose_name = u'поощренных'
        verbose_name_plural = u'Поощренные'
        permissions = (
            ("can_view_apromotion", u"Поощрённые - просмотр."),
        )